<?php


namespace app\common\models;


use app\common\caches\DummyCache;
use app\common\traits\BaseModelOptionTrait;
use think\Model;
use think\model\concern\SoftDelete;
use function GuzzleHttp\json_decode;
use function GuzzleHttp\json_encode;

class DummyJotting extends Model
{
    use BaseModelOptionTrait, SoftDelete;

    protected $table = 'xiangji_dummy_jottings';
    // 自动维护时间戳
    protected $autoWriteTimestamp = true;

    protected $defaultSoftDelete = 0;

    protected $deleteTime = 'delete_time';

    protected $hidden = ['images', 'delete_time'];

    const DAILY_MAX_RECORDS = 5;

    public function setContentAttr($value)
    {
        $preg='/<img.*?\/emoji\/(\d{1,3})\.gif.*?>/is';
        return preg_replace($preg, '[:bq.$1]', $value);
    }

    public function getContentAttr($value)
    {
        $preg='/\[:bq\.(\d{1,3})\]/is';
        return preg_replace($preg, '<img src=\'https://lovetime52.oss-cn-beijing.aliyuncs.com/emoji/$1.gif\'>', $value);
    }

    public function setImagesAttr($value)
    {
        return json_encode($value ?: []);
    }

    public function getImagesAttr($value)
    {
        if (!$value) return [];
        return json_decode($value);
    }
}
